package com.simplefaith.delisty.client.packet.handler;

import static com.simplefaith.delisty.client.packet.opcode.ClientOpCodes.C_Login;
import static com.simplefaith.delisty.client.packet.opcode.ClientOpCodes.Sep;

import com.simplefaith.delisty.client.ClientInstance;
import com.simplefaith.delisty.client.packet.ClientPacket;
import com.simplefaith.delisty.util.PacketUtil;

public class LoginPacketHandler extends PacketHandler {

	private int count = 0;

	public void ReceivePacket(String data) {
		int lastIndex = data.split(Sep).length - 1;
		int key = Integer.valueOf(data.split(Sep)[lastIndex]);
		
		//TODO do some packet stuff... work in progress

		System.out.println("index : " + key);

		getPacket(key).ServerAcceptPacket();
	}

	public LoginPacketHandler() {
		super(C_Login);
	}

	public void HandlePacket(ClientPacket clientPacket) {
		putPacket(count, clientPacket);

		String finalPacket = PacketUtil.ToPacket(clientPacket.getPacket(),String.valueOf(count));
		System.out.println("send PacketMessage " + finalPacket);
		ClientInstance.getClient().sendClientPacket(finalPacket);
		count++;
		System.out.println("send PacketMessage - done");
	}

}
